package com.zlt.miaosha.dao;

import com.zlt.miaosha.domain.Goods;
import com.zlt.miaosha.domain.MiaoshaGoods;
import com.zlt.miaosha.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author zhoulitong
 * @date 2018/6/7
 * @description
 */
@Mapper
public interface GoodsDao {
    @Select("SELECT g.*,mg.stock_count,mg.start_date,mg.end_date FROM miaosha_goods mg LEFT JOIN goods g ON mg.goods_id = g.id")
    public List<GoodsVo> listGoodsVo();

    @Select("SELECT g.*,mg.stock_count,mg.start_date,mg.end_date FROM miaosha_goods mg LEFT JOIN goods g ON mg.goods_id = g.id WHERE mg.goods_id = #{goodsId}")
    public GoodsVo getGoodsVoByGoodsId(@Param("goodsId") long goodsId);

    @Update("update miaosha_goods set stock_count = stock_count-1 where goods_id=#{goodsId} and stock_count>0")
    int reduceStock(MiaoshaGoods g);

    @Update("update miaosha_goods set stock_count = #{stockCount} where goods_id = #{goodsId}")
    public int resetStock(MiaoshaGoods g);
}
